package com.mikufufu.blog.controller.api;

import com.mikufufu.blog.model.entity.Comment;
import com.mikufufu.blog.service.CommentService;
import org.springframework.web.bind.annotation.*;
import com.mikufufu.blog.common.entity.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;

import org.springframework.beans.factory.annotation.Autowired;

@RestController
@RequestMapping("/comment")
@Api(tags = "用户评论接口")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/detail")
    @ApiOperation(value = "获取评论详情", notes = "获取评论详情")
    @ApiImplicitParam(name = "id", value = "评论主键", required = true)
    public  AjaxResult<Comment> detail(Integer id) {
        return AjaxResult.data(commentService.getById(id));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增评论", notes = "新增评论")
    public AjaxResult<Boolean> add(@RequestBody Comment comment) {
        return AjaxResult.status(commentService.save(comment));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改评论",notes = "修改评论")
    public AjaxResult<Boolean> update(@RequestBody Comment comment) {
        return AjaxResult.status(commentService.updateById(comment));
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除评论", notes = "删除评论")
    @ApiImplicitParam(name = "id", value = "评论主键", required = true)
    public AjaxResult<Boolean> delete(Integer id) {
        return AjaxResult.status(commentService.removeById(id));
    }

}
